/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2013
 */

package org.teacup.eightdays.model;

import javax.persistence.*;

import org.hibernate.annotations.GenericGenerator;

import javax.validation.constraints.*;
import org.hibernate.validator.constraints.*;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import org.teacup.eightdays.model.*;
import org.teacup.eightdays.dao.*;
import org.teacup.eightdays.service.*;
import org.teacup.eightdays.vo.query.*;

/**
 * @author Abner email:521yexu2008(a)163.com
 * @version 1.0
 * @since 1.0
 */

@Entity
@Table(name = "school")
public class School extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "School";
	public static final String ALIAS_SCHOOL_ID = "ID";
	public static final String ALIAS_ADDRESS_ID = "学校所在位置";
	public static final String ALIAS_NAME = "学校名称";
	public static final String ALIAS_SYNOPSIS = "学校简介";
	
	//date formats
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * ID       db_column: school_id 
     */ 	
	
	private java.lang.Long schoolId;
    /**
     * 学校所在位置       db_column: address_id 
     */ 	
	
	private java.lang.Long addressId;
    /**
     * 学校名称       db_column: name 
     */ 	
	@NotBlank @Length(max=100)
	private java.lang.String name;
    /**
     * 学校简介       db_column: synopsis 
     */ 	
	@Length(max=2147483647)
	private java.lang.String synopsis;
	//columns END


	public School(){
	}

	public School(
		java.lang.Long schoolId
	){
		this.schoolId = schoolId;
	}

	

	public void setSchoolId(java.lang.Long value) {
		this.schoolId = value;
	}
	
	@Id @GeneratedValue(generator="custom-id")
	@GenericGenerator(name="custom-id", strategy = "increment")
	@Column(name = "school_id", unique = true, nullable = false, insertable = true, updatable = true, length = 19)
	public java.lang.Long getSchoolId() {
		return this.schoolId;
	}
	
	@Column(name = "address_id", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
	public java.lang.Long getAddressId() {
		return this.addressId;
	}
	
	public void setAddressId(java.lang.Long value) {
		this.addressId = value;
	}
	
	@Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
	public java.lang.String getName() {
		return this.name;
	}
	
	public void setName(java.lang.String value) {
		this.name = value;
	}
	
	@Column(name = "synopsis", unique = false, nullable = true, insertable = true, updatable = true, length = 2147483647)
	public java.lang.String getSynopsis() {
		return this.synopsis;
	}
	
	public void setSynopsis(java.lang.String value) {
		this.synopsis = value;
	}
	
	
	private Set deliveryAddresss = new HashSet(0);
	public void setDeliveryAddresss(Set<DeliveryAddress> deliveryAddress){
		this.deliveryAddresss = deliveryAddress;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "school")
	public Set<DeliveryAddress> getDeliveryAddresss() {
		return deliveryAddresss;
	}
	
	private Set departments = new HashSet(0);
	public void setDepartments(Set<Department> department){
		this.departments = department;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "school")
	public Set<Department> getDepartments() {
		return departments;
	}
	
	private Set orderinfos = new HashSet(0);
	public void setOrderinfos(Set<Orderinfo> orderinfo){
		this.orderinfos = orderinfo;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "school")
	public Set<Orderinfo> getOrderinfos() {
		return orderinfos;
	}
	
	private Address address;
	public void setAddress(Address address){
		this.address = address;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "address_id",nullable = false, insertable = false, updatable = false) 
	})
	public Address getAddress() {
		return address;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("SchoolId",getSchoolId())
			.append("AddressId",getAddressId())
			.append("Name",getName())
			.append("Synopsis",getSynopsis())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getSchoolId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof School == false) return false;
		if(this == obj) return true;
		School other = (School)obj;
		return new EqualsBuilder()
			.append(getSchoolId(),other.getSchoolId())
			.isEquals();
	}
}

